define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		//上级分类
		function get_data_cat_list(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"custom_cat": [' +
                    '{"custom_cat_id": 1,"store_id": 1,"parent_id": 1,"is_leaf": false,"cat_name": "手动工具类","disabled": false,"p_order": 1,"goods_count": 10,"child_count": 2},' +
                    '{"custom_cat_id": 2,"store_id": 2,"parent_id": 2,"is_leaf": true,"cat_name": "电动工具类","disabled": false,"p_order": 2,"goods_count": 102,"child_count": 1}]},' +
                    '"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                    return JSON.parse(result);
            }
            else
            return result;
        }
		//编辑
		function get_data_edit(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"custom_cat_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		
		//分类
		function get_data_cat_get(result) {
            if(false) {
                result = '{"success": true,"msg": "","result": {"custom_cat": [' +
                    '{"custom_cat_id": 1,"store_id": 1,"parent_id": 1,"is_leaf": false,"cat_name": "手动工具类","disabled": false,"p_order": 1,"goods_count": 10,"child_count": 2},' +
                    '{"custom_cat_id": 2,"store_id": 2,"parent_id": 2,"is_leaf": true,"cat_name": "电动工具类","disabled": false,"p_order": 2,"goods_count": 102,"child_count": 1}]},' +
                    '"session": "7311da98bd0f18eb15a96bcb263f4153"}';
                    return JSON.parse(result);
            }
            else
            return result;
        }
		
		//返回信息
		return {
			cat_get: function(callback) {
				Http.post({
					method: 'goods.cat.list.get',
				}, function(result) {
                    if(callback)
                     	callback(get_data_cat_get(result).result);
                }, function(e) {

                }, function() {

                })
			},
			get_edit: function(custom_cat_id,parent_id, p_order, cat_name, cat_image, callback) {
				var params = new Object();
				params.parent_id = parent_id;
				params.p_order = p_order;
				params.cat_name = cat_name;
				params.cat_image = cat_image;
				params=JSON.stringify(params);
				Http.post({
					method: 'goods.cat.list.add',
					custom_cat_id:custom_cat_id,
					updateParams:params
				}, function(result) {
                    if(callback)
                     	callback(get_data_edit(result));
                }, function(e) {

                }, function() {

                })
			},
			//显示自定义分类信息
			cat_list: function(custom_cat_id,add_second,callback) {
                Http.post({
                    method:'goods.cat.list.detail',
                    custom_cat_id:custom_cat_id,
                    add_second:add_second
                }, function(result) {
                    //函数回调
                    if(callback)
                        callback(get_data_cat_list(result).result);
                },function(e){

                },function(){

                });
            }
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Productmanager_sort_edit", factory);
});